package com.example.demo1.mapper;

import com.example.demo1.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface ArticleMapper {

    //新增文章
//    @Insert("insert into article(title,content,cover_img,state,category_id,create_user,create_time,update_time)" +
//            "value(#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    @Insert("insert into article(title,content,state,category_id,create_user,create_time,update_time)" +
            "value(#{title},#{content},#{state},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void add(Article article);

    //条件分页列表查询
//    List<Article> list(Integer id, Integer categoryId, String state);
    List<Article> list(Integer id, Integer categoryId, String state, String content);

    //根据id找图片地址
    @Select("select cover_img from article where id = #{id}")
    String uploadSelect(Integer id);

    //更新封面
    @Update("update article set cover_img = #{coverImg} where id = #{id}")
    void upload(String coverImg, Integer id);

//    @Insert("insert into article(cover_img) value(#{coverImg})")
//    void addimg(String coverImg);
//
    @Select("select article.id from article where create_time = #{createTime}")
    Integer idSelect(String createTime);

    //更新文章
    @Update("update article set title = #{title}, content = #{content}, state = #{state}, category_id = #{categoryId}, " +
            "update_time = #{updateTime} where id = #{id}")
    void update(Article article);

    //删除文章
    @Delete("delete from article where id = #{id}")
    void deleteById(Integer id);
}
